|
1
|
|
|
import { byTestId } from '../selectors'; |
|
2
|
|
|
import { ElementHandle } from 'puppeteer'; |
|
3
|
|
|
import { getElementBBox } from '../graph.helpers'; |
|
4
|
|
|
|
|
5
|
|
|
export class Overview { |
|
6
|
|
|
public async getNodes() { |
|
7
|
|
|
await page.waitForSelector(byTestId('node')); |
|
8
|
|
|
return page.$$(byTestId('node')); |
|
9
|
|
|
} |
|
10
|
|
|
|
|
11
|
|
|
public async getNodesText(nodes: ElementHandle[]) { |
|
12
|
|
|
return Promise.all(nodes.map(this.getNodeText)); |
|
13
|
|
|
} |
|
14
|
|
|
|
|
15
|
|
|
public async getNodesTooltipText(nodes: ElementHandle[]) { |
|
16
|
|
|
// hover each node sequentially |
|
17
|
|
|
let tooltipTexts = []; |
|
18
|
|
|
for (const node of nodes) { |
|
19
|
|
|
await node.hover(); |
|
20
|
|
|
await page.waitForSelector(byTestId('tooltip'), { visible: true }); |
|
21
|
|
|
const tooltip = await page.$(byTestId('tooltip')); |
|
22
|
|
|
const tooltipText = await tooltip?.getProperty('textContent'); |
|
23
|
|
|
tooltipTexts.push(await tooltipText?.jsonValue()); |
|
24
|
|
|
} |
|
25
|
|
|
return tooltipTexts; |
|
26
|
|
|
} |
|
27
|
|
|
|
|
28
|
|
|
public async getHighlightedClickedNodeText() { |
|
29
|
|
|
const allNodes = await this.getNodes(); |
|
30
|
|
|
|
|
31
|
|
|
let clickedNode: ElementHandle | undefined; |
|
32
|
|
|
|
|
33
|
|
|
for (const node of allNodes) { |
|
34
|
|
|
const { labelColor, textColor } = await this.getNodeColors(node); |
|
35
|
|
|
|
|
36
|
|
|
if (labelColor === '#071D49' && textColor === '#FFFFFF') { |
|
37
|
|
|
clickedNode = node; |
|
38
|
|
|
break; |
|
39
|
|
|
} |
|
40
|
|
|
} |
|
41
|
|
|
|
|
42
|
|
|
if (clickedNode === undefined) { |
|
43
|
|
|
return ''; |
|
44
|
|
|
} |
|
45
|
|
|
|
|
46
|
|
|
return this.getNodeText(clickedNode); |
|
47
|
|
|
} |
|
48
|
|
|
|
|
49
|
|
|
public async getHighlightedConnectedNodesTexts() { |
|
50
|
|
|
const allNodes = await this.getNodes(); |
|
51
|
|
|
|
|
52
|
|
|
const highlightedNodes = []; |
|
53
|
|
|
|
|
54
|
|
|
for (const node of allNodes) { |
|
55
|
|
|
const { labelColor, textColor } = await this.getNodeColors(node); |
|
56
|
|
|
|
|
57
|
|
|
if (labelColor === '#00C29E' && textColor === '#FFFFFF') { |
|
58
|
|
|
highlightedNodes.push(node); |
|
59
|
|
|
} |
|
60
|
|
|
} |
|
61
|
|
|
|
|
62
|
|
|
return this.getNodesText(highlightedNodes); |
|
63
|
|
|
} |
|
64
|
|
|
|
|
65
|
|
|
public async isHighlightBackgroundVisible() { |
|
66
|
|
|
const background = await this.getHighlightBackground(); |
|
67
|
|
|
return Number(await background?.evaluate(el => (el as SVGRectElement).style.opacity)) > 0; |
|
68
|
|
|
} |
|
69
|
|
|
|
|
70
|
|
|
public async clickOutsideNode() { |
|
71
|
|
|
const background = await this.getHighlightBackground(); |
|
72
|
|
|
await background?.click(); |
|
73
|
|
|
} |
|
74
|
|
|
|
|
75
|
|
|
public async dragNode(node: ElementHandle) { |
|
76
|
|
|
const { x, y, width, height } = await getElementBBox(node); |
|
77
|
|
|
|
|
78
|
|
|
await page.mouse.move(x + width / 2, y + height / 2); |
|
79
|
|
|
await page.mouse.down(); |
|
80
|
|
|
await page.mouse.move(x - 100, y - 100); |
|
81
|
|
|
await page.waitFor(100); |
|
82
|
|
|
await page.mouse.up(); |
|
83
|
|
|
} |
|
84
|
|
|
|
|
85
|
|
|
private async getNodeText(node: ElementHandle) { |
|
86
|
|
|
const textContent = await node.getProperty('textContent'); |
|
87
|
|
|
return textContent.jsonValue(); |
|
88
|
|
|
} |
|
89
|
|
|
|
|
90
|
|
|
private async getNodeColors(node: ElementHandle) { |
|
91
|
|
|
const labelColor = await node.$eval('path', el => el.getAttribute('fill')); |
|
92
|
|
|
const textColor = await node.$eval('text', el => el.getAttribute('fill')); |
|
93
|
|
|
|
|
94
|
|
|
return { labelColor, textColor }; |
|
95
|
|
|
} |
|
96
|
|
|
|
|
97
|
|
|
private async getHighlightBackground() { |
|
98
|
|
|
return page.$(byTestId('highlight-background')); |
|
99
|
|
|
} |
|
100
|
|
|
} |
|
101
|
|
|
|